package com.awspaas.user.apps.processforsap.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TaskValidateForFIUpdate extends InterruptListener implements InterruptListenerInterface {
    @Override
    public boolean execute(ProcessExecutionContext ctx) throws Exception {
        /**
         * 电子
         */
        boolean isty = ctx.isChoiceActionMenu("提交");
        if (isty) {
            //取值
            BO bo = ctx.getBO("BO_EU_SAP_FIZCCHANGE");
            String xglx = bo.getString("XGLX");
            String bukrs= bo.getString("BUKRS");
            String newbukrs = "FH00".equals(bukrs)?"FE":"FS";
            if ("信息修改".equals(xglx)){
                List<BO> list = SDK.getBOAPI().query("BO_EU_SAP_FICL2").bindId(bo.getBindId()).list();
                for (BO bo1:list){
                    String kostlv= bo1.getString("KOSTLV");
                    String kostl= bo1.getString("KOSTL");
                    if (kostlv.startsWith(newbukrs)&&kostl.startsWith(newbukrs)){

                    }else{
                        throw new BPMNError("0331", "所选公司代码与信息修改明细中的调拨后成本中心/调拨后责任成本中心不匹配！");
                    }
                }
            }
        }
        return true;
    }
}
